package com.wisdom;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.wisdom.http.HttpRequestUrl;
import com.wisdom.http.HttpUserService;
import com.wisdom.utils.ActivityUtil;
import com.wisdom.utils.StringUtils;
import com.wisdom.vo.Users;


//相对小编说什么
public class ILoveEditorActivity extends Activity 
{
	private EditText et_title,et_content;
	//private Intent intent;
	private Map<String,String> parmes;
	private HttpUserService userService;
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_iloveeditor);
        initView();
    }
    
	private void initView() 
	{
		et_title = (EditText) findViewById(R.id.et_title);
		et_content = (EditText) findViewById(R.id.et_content);
		userService = new HttpUserService();
	}
	
	//发送发送
	public void sendMyLove(View view)
	{
		String title = et_title.getText().toString();
		String content = et_content.getText().toString();
		
		if(StringUtils.isBlank(title))
		{
			ActivityUtil.toast(this,"至少要有个标题吧？");
			return;
		}
		
		if(StringUtils.isBlank(content))
		{
			ActivityUtil.toast(this,"这是无言的爱吗？");
			return;
		}
		
		if(Users.user == null)
		{
			Intent intent = new Intent(ILoveEditorActivity.this, LoginActivity.class);
			ILoveEditorActivity.this.startActivityForResult(intent, 3);

			return;
		}

		parmes = new HashMap<String, String>();
		
		parmes.put("suggestion.suggestionUserId", Users.user.getUserId() + "");		
		parmes.put("suggestion.suggestionTitle", title);		
		parmes.put("suggestion.suggestionContent", content);
		parmes.put("suggestion.suggestionIP", ActivityUtil.getLocalIpAddress());
	
		String data = userService.requestByPost(HttpRequestUrl.url(HttpRequestUrl.USER_SUGGESTION), parmes);
		//Users.user = userService.parserUser(data);
		
		if(data.equals("true"))
		{
			ActivityUtil.toast(this, "成功了!你的心意小编会知道的");
		}
		else
		{
			ActivityUtil.toast(this, "传送失败");
		}
		
		
		this.setResult(RESULT_OK);
		finish();
		
		
	}

	//跳转到主页面
	public void returnIndex(View view)
	{
		this.setResult(RESULT_OK);
		finish();
	}
	
    
}